package com.cn.mtm2000.mtmgeneratorsqlutil.mtmgeneratorsqlutil.generatorutil;


import com.cn.mtm2000.mtmgeneratorsqlutil.mtmgeneratorsqlutil.generatorutil.config.GenerateSqlmapConfigTools;
import com.cn.mtm2000.mtmgeneratorsqlutil.mtmgeneratorsqlutil.generatorutil.config.SqlMapConfig;
import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.internal.DefaultShellCallback;

import java.io.File;
import java.util.ArrayList;
import java.util.List;


public class GeneratorSqlmapUtil {

	public void generator() throws Exception {

		List<String> warnings = new ArrayList<String>();
		boolean overwrite = true;
		File configFile = new File("generatorConfig.xml");
		ConfigurationParser cp = new ConfigurationParser(warnings);
		Configuration config = cp.parseConfiguration(configFile);
		DefaultShellCallback callback = new DefaultShellCallback(overwrite);
		MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
		myBatisGenerator.generate(null);

	}

	public void generator2(String filePath) throws Exception {

		List<String> warnings = new ArrayList<String>();
		boolean overwrite = true;
		File configFile = new File(filePath);
		ConfigurationParser cp = new ConfigurationParser(warnings);
		Configuration config = cp.parseConfiguration(configFile);
		DefaultShellCallback callback = new DefaultShellCallback(overwrite);
		MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
		myBatisGenerator.generate(null);

	}
	public static void main(String[] args) throws Exception {
		try {
			GeneratorSqlmapUtil generatorSqlmap = new GeneratorSqlmapUtil();
//
//			GenerateSqlmapConfigTools toolsOracle = new GenerateSqlmapConfigTools("oracle.jdbc.driver.OracleDriver","jdbc:oracle:thin:@58.247.46.126:1521:orcl","stdv4_0_dev", "stdv4_0_dev","D:/mapper/oracle");
//
			GenerateSqlmapConfigTools toolsMysql = new GenerateSqlmapConfigTools(
					"com.mysql.jdbc.Driver",
					"jdbc:mysql://172.16.1.12:3306/waste",
					"root", "root", "waste", "D:/MTM_work/mysql");
			//
			SqlMapConfig conf = new SqlMapConfig("t_user", "cn.com.mtmming2000.web.model", "cn.com.mtmming2000.web.mapper");
//			toolsOracle.addTable(conf);
			toolsMysql.addTable(conf);
//			String filePathOracle = toolsOracle.generateXmlFile("D:/mapper/oracle/file.xml");
			String filePathMysql = toolsMysql.generateXmlFile("D:/MTM_work/mysql/file.xml");
//			generatorSqlmap.generator2("D:/mapper/oracle/file.xml");
			generatorSqlmap.generator2("D:/MTM_work/mysql/file.xml");

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}